package edu.hcmus.sow.dao;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import edu.hcmus.sow.domain.Group;

/**
 * DAO to manage Group entities.
 * 
 */
@Repository
@Transactional
public class GroupDAOImpl extends AbstractHibernateDAO<Group, Integer> implements GroupDAO {
   public List<Group> getGroups(Integer clientID) throws DataAccessException {
      String query = "from Group g join fetch g.userByCreatedBy u ";
      query += "where g.clientID = ?";
      return executeQuery(query, clientID);
   }

   public List<Group> findGroupByName(Integer clientID, String name) throws DataAccessException {
      return findByCriteria(Restrictions.eq("clientID", clientID), Restrictions.eq("name", name));
   }
}
